<template>
	<view class="tixian">
		<view class="title">
			修改密码
		</view>
		<view class="tixianbox">
				<view class="item">
				<text>旧密码</text>
				<input type="password" v-model="oldpasswd" placeholder="请输入密码" />
			</view>
			<view class="item">
				<text>新密码</text>
				<input type="password" v-model="newpasswd" placeholder="请输入密码" />
			</view>
			<view class="item"> 
				<text>确认密码</text>
				<input type="password" v-model="comfirmpasswd"   placeholder="请确认密码" />
			</view>
              <view class="kong"></view>
		</view>
		<button class="queren" @click="update" >完成</button>
		
	</view>
</template>

<script>
		import { mapState } from 'vuex'
export default {
	
	data() {
		return {
			
			codemsg: '点击获取',
			btnflag: true,
		
			code:'',
			oldpasswd: '',
			newpasswd: '',
			comfirmpasswd: ''
			
	
		};
	},
		computed: mapState({
		
		

	}),
	onLoad() {
		
		
	},
	methods: {
				update() {
			if (this.oldpasswd == '' || this.newpasswd == '') {
				uni.showToast({
					title: '密码不能为空',
					icon: 'none'
				});
			} else {
				if (this.oldpasswd == this.newpasswd) {
					uni.showToast({
						title: '新旧密码不能相同',
						icon: 'none'
					});
				} else if (this.oldpasswd != this.newpasswd) {
					if (this.comfirmpasswd == this.newpasswd) {
						var data = {
							old_pass: this.oldpasswd,
							new_pass: this.newpasswd,
							token: uni.getStorageSync('token')
						};
						this.$store.dispatch('updatepasswd', data).then(res => {
							if (res.data.code == 1) {
								uni.showToast({
									title: `密码修改成功!,请牢记新密码`,
									icon: 'none'
								});
								uni.setStorageSync('password', "");
								setTimeout(()=>{
									uni.switchTab({
										url:'../user/index'
									})
								},300)
								
								// uni.reLaunch({
								// 	url:'../../pages/login/login'
								// })
							} else if (res.data.code == 0) {
								uni.showToast({
									title: res.data.msg,
									icon: 'none'
								});
							}
						});
					}
					else{
						uni.showToast({
							title: `请确认密码是否一致!`,
							icon: 'none'
						});
					}
				}
			}
		}
	
	
	}
};
</script>

<style lang="scss" scoped >
	.tixian {
		// min-height: calc(100vh - 50upx);
		min-height: 100%;
	   padding: 0 80rpx;
		.title{
			font-size: 60rpx;
			padding: 60rpx 0;
			
		}
		.tixianbox {
			// .kong{
			// 	min-height: 10vh;
			// 	 
			// }
			
			.item {
				background-color: #fff;
				display: flex;
				margin: 0upx 0upx 30upx 0upx;
				// height: 80upx;
				align-items: center;
			   padding-top: 20rpx;
			   padding-bottom: 20rpx;
				font-size: 30upx;
				
				border-bottom: solid 2rpx #d4d4d4;
				text {
					width: 120upx;
				}
				input {
					width: 450upx;
					text-align: right;
				}
				span{
					display: inline-block;
					width: 490upx;
					color: grey;
					// width: 100%;
					text-align: right;
				}
			}
			.item1 {
				margin: 30upx 0upx 0upx 0upx;
				 padding-top: 20rpx;
				
				display: flex;
				flex-direction: row;
				justify-content: space-between;
				view {
					width: 424upx;
					background-color: #ffffff;
					
					display: flex;
					flex-direction: row;
					align-items: center;
					border-bottom:  solid 2rpx #d4d4d4;
					padding-bottom: 20rpx;
					text {
						// padding-left: 40upx;
						font-size: 30upx;
						display: inline-block;
						width: 120upx;
					}
					input {
						// height: 80upx;
						font-size: 28upx;
						
					}
				}
				
				button {
					width: 222rpx;
		height: 60rpx;
					line-height: 60rpx;
					border-radius: 33rpx;
					background-color: #2296f3;
					color: #fff;
					font-size: 28upx;
					margin-left: 30rpx;
				}
			}
		}
		.queren {
			// position: absolute;
			// left: 0;
			// right: 0;
			margin: 0 auto;
			// bottom: 100rpx;
			
			margin-top: 40vh;
			width: 590upx;
			height: 90upx;
			background-color: #2296f3;
				border-radius: 40rpx;
			color: #fff;
			line-height: 90upx;
			font-size: 32upx;
			
		}
	}
	
</style>
